import md5 from 'md5'

// App key
let app = 'testkey'
// App secret, please contact to UNIONAPI administrator
let key = 'testkey'

var {slice} = []
const time = () => (new Date()).valueOf()

export function defaults (target) {
  var args = slice.call(arguments, 1)
  args.forEach(source => {
    for (var key in source) {
      if (target[key] === undefined) {
        target[key] = source[key]
      }
    }
  })
  return target
}

export default function tokens (options) {
  let stamp = time()
  options = options || {}
  options.params = defaults({
    'hash': md5(stamp + key),
    'timestamp': stamp,
    'app': app
  }, options.params || {})
  return options
}
